package com.study.dao.impl;

import com.study.dao.AppInfoDao;
import com.study.entity.AppInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by Administrator on 2017/10/25.
 */
@Repository
public class AppInfoDaoImpl implements AppInfoDao {
    @Autowired
    private HibernateTemplate hibernateTemplate;
    @Override
    public void hitShelves(Integer appId) {

    }

    @Override
    public void offShelves(Integer appId) {

    }

    @Override
    public List<AppInfo> findList(AppInfo appInfo, Integer page, Integer size) {
        return hibernateTemplate.findByExample(appInfo,(page-1)*size,size);
    }


    @Override
    public AppInfo findOneById(Integer id) {
        return hibernateTemplate.get(AppInfo.class,id);
    }

    @Override
    public List<AppInfo> findList(AppInfo appInfo) {
        return hibernateTemplate.findByExample(appInfo);
    }

    @Override
    @Transactional
    public int updateOne(AppInfo appInfo) {
        hibernateTemplate.update(appInfo);
        return 1;
    }

    @Override
    @Transactional
    public int saveOne(AppInfo appInfo) {
        return (int) hibernateTemplate.save(appInfo);
    }

    @Override
    @Transactional
    public int deleteById(Integer id) {
        return 0;
    }
}
